package com.common.base.widget.indicators

import android.content.Context
import android.graphics.Typeface
import android.util.TypedValue
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ColorTransitionPagerTitleView

/**
 *
 * 作者：sosou
 *
 * 版本：1.0
 *
 * 创建日期：2023/2/4
 *
 * 描述：带颜色渐变和缩放的指示器标题以及选中字体样式改变
 *
 * 修订历史：
 *
 */
class SScaleTransitionPagerTitleView : ColorTransitionPagerTitleView {
    private var mMinScale = 0.95f
    private var selectTextSize = 0F

    constructor(context: Context?) : super(context) {}

    constructor(context: Context?, selectTextSize: Float) : super(context) {
        this.selectTextSize = selectTextSize
    }

    constructor(context: Context?, normalTextSize: Float, selectTextSize: Float) : super(context) {
        this.textSize = normalTextSize
        this.selectTextSize = selectTextSize
    }

    override fun onEnter(index: Int, totalCount: Int, enterPercent: Float, leftToRight: Boolean) {
        super.onEnter(index, totalCount, enterPercent, leftToRight) // 实现颜色渐变
        scaleX = mMinScale + (1.0f - mMinScale) * enterPercent
        scaleY = mMinScale + (1.0f - mMinScale) * enterPercent
        typeface = Typeface.DEFAULT_BOLD //选中后的字体样式,根据需求自己做修改
//        if (selectTextSize > 0) {
//            setTextSize(TypedValue.COMPLEX_UNIT_SP, selectTextSize)
//        }
        typeface = Typeface.defaultFromStyle(Typeface.BOLD)
    }

    override fun onLeave(index: Int, totalCount: Int, leavePercent: Float, leftToRight: Boolean) {
        super.onLeave(index, totalCount, leavePercent, leftToRight) // 实现颜色渐变
        scaleX = 1.0f + (mMinScale - 1.0f) * leavePercent
        scaleY = 1.0f + (mMinScale - 1.0f) * leavePercent
        typeface = Typeface.DEFAULT //未选中的字体样式,根据需求自己做修改
        typeface = Typeface.defaultFromStyle(Typeface.NORMAL)//未选中的字体样式,根据需求自己做修改
//        if (normalTextSize > 0) {
//            setTextSize(TypedValue.COMPLEX_UNIT_SP, normalTextSize)
//        }
    }

//    override fun setTextSize(size: Float) {
//        normalTextSize = size
//        super.setTextSize(size)
//    }

    fun getMinScale(): Float {
        return mMinScale
    }

    fun setMinScale(minScale: Float) {
        mMinScale = minScale
    }
}